{% extends "master.html" %} {% block title %}{% end %} {% block header%}{% end %} {% block sidebar_header %}{% end %}
{% block content_header_title%} {{current_screen.current_menu["menu_title"]}} {% end %} {% block content_header_breadcrumb%}{% end %}
{% block content_body%}
<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-body">
                <!-- form start -->
                <form role="form" id="options-general-form">
                    {% raw apply_filters("bo_options_general_form", "", current_screen) %}
                    <input type="hidden" id="option_name" name="option_name" value="{{current_screen.id}}"/>
                    {% module xsrf_form_html() %}
                </form>
            </div>
        </div>
    </div>
    <div class="col-md-12">
        <button type="button" class="btn btn-primary pull-right" id="options-general-btn">保存</button>
    </div>
</div>
{% end %} {% block footer%}
<script type="text/javascript">
    jQuery(function ($) {
        $.post("{{api('bo_options_general_get')}}", bo_xsrf({"option_name": $("#option_name").val()}), function (data) {
            $("#options-general-form").find(".form-control").each(function () {
                var elem_name = $(this).attr("name");
                if (elem_name != undefined || elem_name != null || $.trim(elem_name) != "") {
                    var remote_v = data.data[elem_name.replace("opt_", "")];
                    if (remote_v != undefined) {
                        var data_type = $(this).attr("type");
                        if (data_type == "radio") {
                            $('input[name="' + elem_name + '"]').each(function () {
                                $(this).prop("checked", false);
                                var v = $(this).val();
                                if ($.inArray(v, remote_v) != -1) {
                                    $(this).prop("checked", true);
                                }
                            });
                        } else if (data_type == "checkbox") {
                            $(this).prop("checked", false);
                            var v = $(this).val();
                            if ($.inArray(v, remote_v) != -1) {
                                $(this).prop("checked", true);
                            }
                        } else {
                            $(this).val(remote_v[0]);
                        }
                    }
                }
            });
        }, "json");
        $("#options-general-btn").click(function () {
            var params = $("#options-general-form").serialize();
            $.post("{{api('bo_options_general_save')}}", params, function (rsp) {
                if (rsp.success) {
                    bo_alert_success("设置保存成功");
                } else {
                    bo_alert_error("设置保存失败");
                }
            }, "json");
        });
    });

</script>
{% end %}